package com.shujia.wyh.day26;

public class DieLock extends Thread{

    private boolean flag;
    DieLock(boolean flag){
        this.flag = flag;
    }

    @Override
    public void run() {
        if(flag){
            synchronized (MyLock.lock1){
                System.out.println("if lock1");
                synchronized (MyLock.lock2){
                    System.out.println("if lock2");
                }
            }
        }else {
            synchronized (MyLock.lock2){
                System.out.println("else lock2");
                synchronized (MyLock.lock1){
                    System.out.println("else lock1");
                }
            }
        }
    }
}
